package linklist;

public class L0207 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        int i=0,j=0;
        ListNode curra=headA;
        ListNode currb=headB;
        while(curra!=null){
            i+=1;
            curra=curra.next;
        }
        while(currb!=null){
            j+=1;
            currb=currb.next;
        }
        curra=headA;
        currb=headB;
        if (j>i){
            int temp=i;
            i=j;
            j=temp;
            ListNode tempnode=curra;
            curra=currb;
            currb=tempnode;
        }//执行完这个后现在都是a的列表长度较长，且i对应的是长列表，j对应的是短列表长度
        int cha=i-j;
        while (cha-->0){
            curra=curra.next;
        }
        while (curra!=null){

            if (curra==currb){
                return curra;
            }
            curra=curra.next;
            currb=currb.next;

        }
        return null;
    }
}
